<?php

function update_table(){
	 
	$query = "SELECT * FROM a_surat_ijin WHERE MONTH(tanggal) = '01' ORDER BY tanggal ASC";
	$result = my_query($query);
	while($t = my_fetch_array($result)){
		$nomor = getNumber('2011','01');
		$datas = array(
			'nomor_surat'=>my_type_data_str($nomor)
		);
		my_update_record('a_surat_ijin','surat_ijin_id',$t['surat_ijin_id'],$datas);
	}
	}
}

function getNumber($tahun,$bulan){
	$query = "SELECT max(nomor_surat) as nn FROM a_surat_ijin 
		WHERE YEAR(tanggal) = '{$tahun}' AND MONTH(tanggal) ='{$bulan}' ";
	$res = my_query($query);
	$row = my_fetch_array($res);
	return $tahun.$bulan.substr($row['nn'] ,6,12) + 1;
}